package org.msss.sprites;

import org.msss.gamebasic.*;
import org.lwjgl.input.Keyboard;
import java.util.ArrayList;

/**
 * Direction, 0 is right, 1 is down, 2 is left, 3 is up
 * 
 * @author alanxoc3
 * 
 */
public class Direction extends Sprite {

	private ArrayList<Integer> directionList;

	@Override
	public void create() {
		directionList = new ArrayList<Integer>();
		
		setVisible(false);
	}

	@Override
	public void pressed(int key) {

		// Control 1
		switch (key) {
		case Keyboard.KEY_RIGHT:
			directionList.add(0);
		case Keyboard.KEY_DOWN:
			directionList.add(3);
		case Keyboard.KEY_LEFT:
			directionList.add(2);
		case Keyboard.KEY_UP:
			directionList.add(1);
		}

		// Control 2
		switch (key) {
		case Keyboard.KEY_D:
			directionList.add(0);
		case Keyboard.KEY_S:
			directionList.add(3);
		case Keyboard.KEY_A:
			directionList.add(2);
		case Keyboard.KEY_W:
			directionList.add(1);
		}

		if (directionList.size() > 0) {
			setDirection(directionList.get(0) * 90);
		}
	}

	@Override
	public void released(int key) {

		// Control 1
		switch (key) {
		case Keyboard.KEY_RIGHT:
			directionList.remove(new Integer(0));
		case Keyboard.KEY_DOWN:
			directionList.remove(new Integer(3));
		case Keyboard.KEY_LEFT:
			directionList.remove(new Integer(2));
		case Keyboard.KEY_UP:
			directionList.remove(new Integer(1));
		}

		// Control 2
		switch (key) {
		case Keyboard.KEY_D:
			directionList.remove(new Integer(0));
		case Keyboard.KEY_S:
			directionList.remove(new Integer(3));
		case Keyboard.KEY_A:
			directionList.remove(new Integer(2));
		case Keyboard.KEY_W:
			directionList.remove(new Integer(1));

		}
		
		if (directionList.size() > 0) {
			setDirection(directionList.get(0) * 90);
		}
	}
}
